package org.jfbmonitor.view.transaction;

import java.text.DateFormat;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.jfbmonitor.beans.Transaction;

public class TransactionTableModel extends AbstractTableModel {	
	private static final long serialVersionUID = 1L;
	private List<Transaction> transactions; 
	
	public TransactionTableModel( List<Transaction> transactions ){
		this.transactions = transactions;
	}

	@Override
	public int getColumnCount() {		
		return 13;
	}

	@Override
	public int getRowCount() {		
		return this.transactions.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Transaction transaction = this.transactions.get(rowIndex);
		DateFormat dt = DateFormat.getDateTimeInstance();
		switch ( columnIndex ) {
		   case 0: return  transaction.getTransactionId();		   
		   case 1: return  transaction.getAttachment().getAttachmentId();
		   case 2: return  transaction.getState();
		   case 3: return  dt.format(transaction.getTimeStamp());
		   case 4: return  transaction.getTopTransaction();
		   case 5: return  transaction.getOldestTransaction();
		   case 6: return  transaction.getOldestActive();
		   case 7: return  transaction.getIsolationMode();
		   case 8: return  transaction.getLockTimeOut();
		   case 9: return  transaction.getReadOnly();
		   case 10: return transaction.getAutoCommit();
		   case 11: return transaction.getAutoUndo();
		   case 12: return transaction.getStatId();		    
		}		
		return null;
	}
	
	public Transaction getValuesTransaction( int rowIndex ){
		return transactions.get(rowIndex);
	}
	
	

}
